ARG APP_NAME=todo

#编译镜像
FROM golang:1.24.0-alpine AS builder

ARG APP_NAME
LABEL stage=builder_${APP_NAME}

#工作区
WORKDIR /home/work/${APP_NAME}/
COPY . .

#编译环境
ENV GO111MODULE=on
ENV GOSUMDB=off
ENV GOPROXY=https://goproxy.cn|direct

#开始编译
RUN go build -o ${APP_NAME}

#运行镜像
FROM alpine
ARG APP_NAME
ENV APP_NAME_ENV ${APP_NAME}
LABEL stage=stable_${APP_NAME}

#工作区
WORKDIR /home/work/${APP_NAME}/

#拷贝命令到当前镜像
COPY --from=builder /home/work/${APP_NAME}/${APP_NAME} .
COPY --from=builder /home/work/${APP_NAME}/conf  conf/

RUN mkdir -p /home/work/${APP_NAME}/logs

#更新apl源、更新时区
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk update && apk --no-cache add tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && chmod +x ./${APP_NAME}

ENV TZ Asia/Shanghai

RUN mkdir -p /home/work/${APP_NAME}/logs

#启动命令
ENTRYPOINT ./${APP_NAME_ENV} $0 $@